import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'logic.dart';

class FriendsPage extends StatelessWidget {
  FriendsPage({Key? key}) : super(key: key);

  final logic = Get.put(FriendsLogic());
  final state = Get.find<FriendsLogic>().state;
  bool hasFriends = true;
  int itemCount = 10;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(LocaleKeys.space_friend.ts, style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back()),
        actions: [
          Visibility(
              visible: hasFriends,
              replacement: Container(),
              child: Container(
                  width: 68.w,
                  height: 68.w,
                  margin: EdgeInsets.only(right: 42.w),
                  child: Image.asset('assets/images/space/icon_friends_add.png', fit: BoxFit.fill,)
              ))
        ],
      ),
      body: hasFriends?_friendList():_emptyFriends(),
    );
  }

  Widget _emptyFriends() {
    Widget widget = Container(
      margin: EdgeInsets.fromLTRB(42.w, 100.h, 42.w, 0),
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.fromLTRB(58.w, 60.h, 58.w, 60.h),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(10)
            ),
            child: Row(
              children: [
                Container(
                  width: 220.w,
                  height: 220.w,
                  margin: EdgeInsets.only(right: 60.w),
                  decoration: BoxDecoration(
                      color: ColorConst.accentColor,
                      borderRadius: BorderRadius.circular(50)
                  ),),
                Text(LocaleKeys.friends_scan_qrcode.ts, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor),),
              ],
            ),
          ),
          Container(
              width: 730.w,
              height: 730.w,
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 223.h),
              child: Image.asset('assets/images/device/device_qrcode.png', fit: BoxFit.fill,)
          ),
        ],
      ),
    );
    return widget;
  }

  Widget _friendList() {
    Widget widget = ListView.builder(
        padding: EdgeInsets.only(left: 42.w, right: 42.w),
        itemCount: itemCount,
        itemBuilder: (context, index){
          return Container(
            margin: EdgeInsets.only(top: index==0?100.h:40.h, bottom: index==itemCount-1?100.h:0),
            padding: EdgeInsets.fromLTRB(58.w, 60.h, 52.w, 60.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(10)
            ),
            child: Row(
              children: [
                Container(
                  width: 220.w,
                  height: 220.w,
                  margin: EdgeInsets.only(right: 60.w),
                  decoration: BoxDecoration(
                      color: ColorConst.accentColor,
                      borderRadius: BorderRadius.circular(50)
                  ),),
                Expanded(child: Text(LocaleKeys.space_friend.ts, style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor),),),
                Text('12345 ${LocaleKeys.step.ts}', style: TextStyle(fontSize: 42.sp, color: ColorConst.btnFontColor),),
              ],
            ),
          );
        });
    return widget;
  }
}
